home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: Mike Girou <girou@parashift.com>
- Newsgroups: comp.lang.c++
- Subject: Re: NEWBIE: Returning 0 as refernce
- Date: Sun, 10 Mar 1996 19:02:04 -0600
- Organization: Paradigm Shift, Inc.
- Message-ID: <31437B8C.3400@parashift.com>
- References: <4huslk$rpk@badger.wmin.ac.uk> <4hvglg$v4@news4.digex.net>
- NNTP-Posting-Host: ix-dfw18-10.ix.netcom.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-NETCOM-Date: Sun Mar 10 5:02:30 PM PST 1996
- X-Mailer: Mozilla 2.0 (Win95; I)
-
- > Renato Araujo (tqaec@westminster.ac.uk) wrote:
- > : I am trying to write bits of Linux in C++. In order to make it fast I try to
- > : return references instead of pointers (some classes are rather big). But what
- > : is the standard way of returning a reference when it is not found
- >
-
- If the referent is supposed to exist, you might throw an exception
- for the rare cases when it isn't there. If the referent may or may
- not exist, then return a pointer, which can be NULL. You will not
- get any performance improvements with references versus pointers.
- You should generally use references if you can, pointers if you have
- to. References, particular if const, are a valuable way to document
- your assumptions and protect against unintended modifications later.
-
- Mike
-
- --
- Mike Girou girou@parashift.com
-